<template>
	<scroll-view scroll-y class="container" lower-threshold="50" @scrolltolower="scrolltolower" :style="'height:'+height+'px'">
		 		
		<view class="tab-bar-list">
			<view :class="['item',{active:index==categoryIndex}]" v-for="(item,index) in category" @click="slcTab(index)">{{item.name}}</view>
		</view>
		<view class="cont-list">
			<view class="cont-item" v-for="(item,index) in dataArr" @click="gotoDetail(item.id)">
				<view class="cover common-bg-img" :style="'background-image:url('+item.imageUrl+')'"></view>
				<view class="title">{{item.treeDetailNo}}</view>
				<view class="intro">{{item.area}}</view>
				<view class="other flexVerticle">
					<view class="bottomFlex">
						<image class="symbol" src="/static/icon/symbol.png"></image>
						<text class="price">{{item.price / 100.0}}</text>
					</view>
					<view class="btn-box centerFlex">认购</view>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				category:[],
				categoryIndex:0,
				height:0,
				page:1,
				treeId:'',
				isLoad:true,
				dataArr:[],
				swiperCurrent:0,
				swiperLength: 0,
				titleNViewBackground: '',
				carouselList: [],
				newsList: [],
				planList: [{icon:'../../static/home/zhongzhi.png', id:'7', title:'种植技术'}, {icon:'../../static/home/tianjian.png', id:'8', title:'农资科普'}, {icon:'../../static/home/bingchong.png', id:'9', title:'病虫害防治'},{icon:'../../static/home/kepu.png', id:'10', title:'农资商城'}]
			};
		},
		onShow() {
			
		},
		onLoad(options) {
			const that = this
			this.height = uni.getSystemInfoSync().windowHeight
		    this.treeId=options.id
			that.getList();
		},
		onShareAppMessage() {
			const that = this
			return {
				title: '果王来了',
				imageUrl: 'https://shopmalling-asset.oss-cn-hangzhou.aliyuncs.com/share.jpg',
				path: '/pages/index/index'
			}
		},
		methods: {
			getList(reload){
				const that = this
				if(reload){
					this.page = 1
					this.isLoad = true
					this.dataArr = []
				}
				uni.showLoading({
					title: '正在加载'
				})
				
				that.$api.request('tree', 'detailListByTreeId',{treeId:that.treeId,page:that.page}, failres => {
					that.$api.msg(failres.errmsg)
					uni.hideLoading()
				}).then(res => {
					let data = res.data.items
					let arr = that.dataArr
					if(data.length > 0){
						that.isLoad = true
					}
					data.forEach(item => {
						arr.push(item)
					})
					that.dataArr = arr
					uni.hideLoading()
				})
			},
			gotoDetail(id){
				uni.navigateTo({
					url:'/pages/tree/detail?id='+id
				})
			},
			slcTab(index){
				this.categoryIndex = index
				this.getList(true)
			},
			scrolltolower(e){
				if(this.isLoad){
					this.isLoad = false
					let page = this.page;
					this.page = page+1
					this.getList()
				}
			},
			 
			naviageToPage(page) {
				uni.navigateTo({
					url: page
				})
			}
			  
		},
	}
</script>

<style lang="less" scoped>
	.container{
		background-color: #F9F9F9;
	}
	
	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
		// padding-top: 10px;
	
		.titleNview-placing {
			height: var(--status-bar-height);
			// padding-top: 44px;
			box-sizing: content-box;
		}
	
		.titleNview-background {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			// height: 426upx;
			transition: .4s;
		}
	}
	
	.carousel {
		width: 100%;
		height: 350upx;
	
		.carousel-item {
			width: 100%;
			height: 100%;
			padding: 0 28upx;
			overflow: hidden;
		}
	
		image {
			width: 100%;
			height: 100%;
			border-radius: 10upx;
		}
	}
	
	.swiper-dots {
		display: flex;
		position: absolute;
		left: 60upx;
		bottom: 15upx;
		width: 72upx;
		height: 36upx;
		background-image: url();
		background-size: 100% 100%;
	
		.num {
			width: 36upx;
			height: 36upx;
			border-radius: 50px;
			font-size: 24upx;
			color: #fff;
			text-align: center;
			line-height: 36upx;
		}
	
		.sign {
			position: absolute;
			top: 0;
			left: 50%;
			line-height: 36upx;
			font-size: 12upx;
			color: #fff;
			transform: translateX(-50%);
		}
	}
	.farm-box{
		display: flex;
		align-items: center;
		padding:30upx 0 20upx;
		width: 90%;
		margin: 0 auto;

		.farm-left{
			font-size: 30upx;
			display: block;
			padding: 6upx 20upx 6upx 0;
			border-right: solid 6upx #ccc;
			width: 20%;
			.farm-info{
				color: #fff;
				// background-color: #4CD964;
				margin-top: 10upx;
				.farm-imfoimg{
					width: 90upx;
					height: 40upx;
				}
			}
		}
		.farm-right{
			width: 80%;
			margin-left: 18upx;
			.farm-rightlist{
				font-size: 30upx;
				padding: 10upx;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
				// width: 300upx;
				
			}
		}
	}
	
	.planting-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding:30upx 0 20upx;
		width: 90%;
		margin: 0 auto;
		.planting-plan{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 0 13upx;
		}
		.planting-img{
			width: 90upx;
			height: 90upx;
		}
		.planting-title{
			text-align: center;
			font-size: 28upx;
			padding-top: 10upx;
		}
		
	}
	
	.tab-bar-list{
		display: flex;
		align-items: center;
		padding:30upx 0 20upx;
		.item{
			padding:10upx 45upx;
			font-size: 36upx;
			color: #999999;
			&:first-child{
				margin-left:60upx;
			}
			&.active{
				color: #009D44;
				border:2upx solid #009D44;
				border-radius: 60upx;
				font-weight: bold;
			}
			&:not(:last-child){
				margin-right:50upx;
			}
		}
	}
	.cont-list{
		padding:0 32upx;
		.cont-item{
			margin-bottom: 20upx;
			padding:40upx;
			background:rgba(255,255,255,1);
			box-shadow:0px 3upx 29upx 0px rgba(196, 196, 196, 0.35);
			border-radius:20upx;
			.cover{
				width:100%;
				height:297upx;
			}
			.title{
				margin-top: 30upx;
				font-size: 30upx;
				color: #333333;
				font-weight: bold;
			}
			.intro{
				margin-top: 20upx;
				color: #666666;
				font-size: 24upx;
			}
			.other{
				margin-top: 30upx;
				.symbol{
					width:20upx;
					height: 20upx;
					margin:0 8upx 8upx 0;
				}
				.price{
					color: #FF4E00;
					font-size: 40upx;
					line-height: 1;
				}
				.btn-box{
					width:186upx;
					height:70upx;
					margin-left: auto;
					color: #009D44;
					border:2upx solid #009D44;
					border-radius: 60upx;
					font-weight: bold;
					font-size: 30upx;
				}
			}
		}
	}
</style>
